<template>
  <!--任务校核-->
  <div>
    <div class="titleHeader">
      <zh-row :span="24">
        <zh-col :span="8">
      <div class="left">
        <span class="title">{{moduleTitle}}</span>
        &nbsp;&nbsp;
        <span>(数据量{{headerInfo.count}}条)</span>
      </div>
        </zh-col>
        <zh-col :span="15">
      <div class="right">
        <span>最近任务截止时间: {{headerInfo.c0305}}</span> &nbsp;&nbsp;
        <span>已校核: {{headerInfo.checkCount}}条</span> &nbsp;&nbsp;
        <span>未校核: {{headerInfo.noCheckCount}}条</span>
        <span style="width: 170px">  <a-progress :percent=this.headerInfo.taskPlan size="small" /></span>
      </div>
        </zh-col>
      </zh-row>
    </div>

    <div style="margin-top: 5px"></div>

    <zh-row :gutter="[16,16]" :span="24" style="height: 100%; flex-direction: column;">
      <zh-col>
        <zh-card title="查询条件">
          <zh-form ref="userQueryFrom" :model="queryParam">
            <zh-input prop="b0102" label="名称" placeholder="支持模糊查询" v-model="queryParam.b0102"></zh-input>
            <zh-input prop="b0105" type="select" :options="dictData.B0105" label="文保等级"  placeholder="请选择"
                      allowClear v-model="queryParam.b0105"></zh-input>
            <zh-input prop="b0106" type="select" :options="dictData.B0106" label="时代"  placeholder="请选择"
                      allowClear v-model="queryParam.b0106"></zh-input>
            <template v-if="advanced">
              <zh-input prop="c0103" type="select" :options="dictData.C0103" label="校核状态"  placeholder="请选择"
                        allowClear v-model="queryParam.c0103"></zh-input>
              <zh-input prop="c0105" type="select" :options="dictData.C0105" label="审核状态"  placeholder="请选择"
                        allowClear v-model="queryParam.c0105"></zh-input>
              <zh-input prop="c0302" label="任务名称" placeholder="支持模糊查询" v-model="queryParam.c0302"></zh-input>
            </template>
            <a-col :span="24">
              <span class="table-page-search-submitButtons" style="float:right;">
                <a-space :size="20">
<!--                  <a-button type="primary" @click="auditBatch">导入</a-button>-->
                  <!--                  <a-button type="primary" @click="downLoadMyPendExcel">导出</a-button>-->
                  <a-button type="primary" @click="findGJResource">查询</a-button>
                  <a @click="toggleAdvanced">
                      {{ advanced ? '收起' : '展开' }}
                      <a-icon :type="advanced ? 'up' : 'down'"/>
                  </a>
                </a-space>
              </span>
            </a-col>
          </zh-form>
        </zh-card>
      </zh-col>
      <zh-col style="flex: 1;">
        <zh-table :shadow="true" ref="gjResourceListTable" title="资源列表" row-id="userId" :url="tableUrl" :columns="tableColumn"
                  :radio-config="{ trigger: 'row'}"  :disabled="false"  :toolbarConfig="toolbarConfig">
          <template #operate="{ row }">
            <div class="alert-message">
              <i class="fa fa-exclamation-circle alert-message-icon"></i>
              <span class="alert-message-content">
                    <vxe-button status="primary" @click="check(row)" v-if="row.c0103 === '0'">校核</vxe-button>
                    <vxe-button status="primary" @click="queryDetail(row)" v-else>查看</vxe-button>
              </span>
            </div>
          </template>
        </zh-table>
      </zh-col>
    </zh-row>
    <a-modal
        :title="modalTitle"
        centered
        style="top: 20px;"
        width="80%"
        destroyOnClose
        v-model="visible"
        cancelText="关闭"
        okText="保存"
        @ok="handleForm"
    >
      <pointInfo ref="pointInfo" :b0101="b0101" :saveFlag="saveFlag"/>
    </a-modal>

  </div>
</template>

<script>
import {getResourceObjectListForTaskCheck,checkResource,getHeaderInfo} from '@/services/system/whdngxlApi'
import { getBatchDict } from "@/services/system/api"
import modal from "ant-design-vue/lib/modal";
import pointInfo from '@/pages/whdngxl/pointInfo'
export default {
  name: "taskCheck",
  components: {
    pointInfo
  },
  data(){
    return {
      //模块名称
      moduleTitle: '',
      //古迹大的列别 不可移动文物 古树古木等
      c0303: '',
      //数据字典
      dictData: {
        B0105: [],
        B0106: [],
        B0113: [],
        B0114: [],
        C0103: [],
        C0105: [],
      },
      toolbarConfig: {
        custom: true,
      },
      advanced: false,
      tableUrl: getResourceObjectListForTaskCheck,
      tableColumn: [ {type: 'checkbox', width: 50, fixed: 'left'},
        {type: 'seq', width: 60, fixed: 'left', align: 'center', title: '序号'},
        {field: 'b0102', title: '名称', fixed: 'left', align: 'center', width: 150},
        {field: 'b0104Name', title: '古系列类别', align: 'center', width: 150},
        {field: 'b0105Name', title: '文保级别', align: 'center', width: 150},
        {field: 'b0106Name', title: '时代', align: 'center', width: 150},
        {field: 'b0107', title: '县市区', align: 'center', width: 150},
        {field: 'b0108', title: '街道', align: 'center', width: 100},
        {field: 'b0109', title: '地址', align: 'center', width: 100},
        {field: 'b0116', title: '详情', align: 'center', width: 100},
        {field: 'b0117Name', title: '省级文保类别', align: 'center', width: 100},
        {field: 'b0118Name', title: '省级文保子类', align: 'center', width: 100},
        {field: 'c0103Name', title: '校核状态', align: 'center', width: 150},
        {field: 'c0105Name', title: '审核状态', align: 'center', width: 150},
        {field: 'c0302', title: '任务名称', align: 'center', width: 150},
        {field: 'c0304', title: '校核开始时间', align: 'center', width: 150},
        {field: 'c0305', title: '校核截止时间', align: 'center', width: 150},
        {field: 'b0113Name', title: '是否核销', align: 'center', width: 100},
        {field: 'b0114Name', title: '是否安全', align: 'center', width: 100},
        {field: 'b03Info', title: '监控设备', align: 'center', width: 150},
        {field: 'operate', title: '操作', align: 'center',  minWidth: 150,fixed: 'right',slots: {default: 'operate'} }
      ],
      queryParam: {
        b0102: '',//模糊
        b0105: '',
        b0106: '',
        c0103: '',
        c0105: '',
        b0113: '',
        b0114: '',
        c0302: '',//模糊
        filterVOList: []
      },
      selectRule: {
        b0102: {
          data: true,
          fuzzyQuery: true,
        },
        c0302: {
          data: true,
          fuzzyQuery: true,
        },
        b0105: {
          data: true,
        },
        b0106: {
          data: true,
        },
        c0105: {
          data: true,
        },
        b0113: {
          data: true,
        },
        b0114: {
          data: true,
        },
        c0103: {
          data: true,
        },
      },
      b0101: '',
      c0101: '',
      modalTitle: '',
      visible: false,
      headerInfo: {
        count: null,
        checkCount: null,
        noCheckCount: null,
        taskPlan:0,
        c0305:'',
      },
      saveFlag: false,
    }
  },
  created() {
    //数据字典初始化
    this.$http.post(getBatchDict, {dictFields: 'B0105,B0106,C0105,B0113,B0114,C0103'}).then(res => {
      this.dictData = res.result
    })
    if(this.$store.state.user.currentRouter.name === 'URResourcesCheck'){
      //不可移动文物
      this.moduleTitle = '不可移动文物'
      this.c0303 = '1'
    }else if(this.$store.state.user.currentRouter.name === 'TreeResourcesCheck'){
      //古树古木
      this.moduleTitle = '古树古木'
      this.c0303 = '2'
    }else if(this.$store.state.user.currentRouter.name === 'RoadResourcesCheck'){
      //古道
      this.moduleTitle = '古道'
      this.c0303 = '3'
    }
    this.$nextTick(()=>{
      this.getHeaderInfo()
      this.findGJResource()
    })
  },
  methods: {
    //获取任务校核模块头部信息
    getHeaderInfo(){
      this.$http.post(getHeaderInfo, {c0303: this.c0303}).then((res) => {
        this.headerInfo = res.result
      })
    },
    //展开和收起
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    //校核
    check(row){
      this.modalTitle = '校核'
      this.visible = true
      this.b0101 = row.b0101
      this.c0101 = row.c0101
      this.saveFlag = false
    },
    //查看
    queryDetail(row){
      this.modalTitle = '查看'
      this.visible = true
      this.b0101 = row.b0101
      this.saveFlag = true
    },
    handleForm(){
      if(this.modalTitle === '查看'){
        this.visible = false
        return
      }
      this.$refs.pointInfo.saveOrUpdate().then(formData =>{
        console.log(formData)
        formData.c0303 = this.c0303
        formData.b0110 = formData.b0111 + ',' + formData.b0112
        formData.c0101 = this.c0101
        if(formData.b0101 && formData.c0101) {
          //校核
          this.$http.post(checkResource, formData).then((res) => {
            modal.info({title: '成功提示', content: '校核成功'})
            this.visible = false
            this.findGJResource()
            this.getHeaderInfo()
          })
        }
      })
    },
    // 查询古迹资源
    findGJResource() {
      const filterVOList = []
      filterVOList.push({property: 'c0303', data: this.c0303})
      Object.keys(this.queryParam).forEach((key) => {
        if(this.queryParam[key]){
          if(this.selectRule[key] && this.selectRule[key].data === true){
            filterVOList.push({property: key, data: this.queryParam[key],fuzzyQuery: this.selectRule[key].fuzzyQuery})
          }
        }
      })
      this.queryParam.filterVOList = filterVOList;
      this.$refs.gjResourceListTable.query(this.queryParam)
    },
  }
}
</script>

<style lang="less" scoped>
.titleHeader{
  background-color: white;
  .left {
    display: inline-block;
    .title {
      font-size: 24px;
    }
  }
  .right {
    display: block;
    float: right;
  }
}
</style>